import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 动态表单配置行
 * @date 2019-07-15
 */
import request from 'utils/request';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function formLines() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/form-lines") : 'form-lines';
}
/**
 * 查询动态配置行列表
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */


export function fetchLineList(_x) {
  return _fetchLineList.apply(this, arguments);
}
/**
 * 通过 lineId 查询配置行明细
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _fetchLineList() {
  _fetchLineList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines(), "/").concat(params.formHeaderId), {
              method: 'GET',
              query: _objectSpread({}, parseParameters(params))
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchLineList.apply(this, arguments);
}

export function fetchLineById(_x2) {
  return _fetchLineById.apply(this, arguments);
}
/**
 * 新增动态配置行
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _fetchLineById() {
  _fetchLineById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines(), "/detail/").concat(params.formLineId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchLineById.apply(this, arguments);
}

export function createLine(_x3) {
  return _createLine.apply(this, arguments);
}
/**
 * 更新动态配置行
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _createLine() {
  _createLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createLine.apply(this, arguments);
}

export function updateLine(_x4) {
  return _updateLine.apply(this, arguments);
}
/**
 * 删除配置行
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _updateLine() {
  _updateLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateLine.apply(this, arguments);
}

export function removeLine(_x5) {
  return _removeLine.apply(this, arguments);
}
/**
 * 通过表单头code查询启用状态的表单配置行列表
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _removeLine() {
  _removeLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _removeLine.apply(this, arguments);
}

export function fetchListByHeaderCode(_x6) {
  return _fetchListByHeaderCode.apply(this, arguments);
}
/**
 * 通过表单头id查询启用状态的表单配置行列表
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _fetchListByHeaderCode() {
  _fetchListByHeaderCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines(), "/header-code"), {
              method: 'GET',
              query: _objectSpread({}, parseParameters(params))
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchListByHeaderCode.apply(this, arguments);
}

export function fetchListByHeaderId(_x7) {
  return _fetchListByHeaderId.apply(this, arguments);
}

function _fetchListByHeaderId() {
  _fetchListByHeaderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formLines(), "/header-code"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _fetchListByHeaderId.apply(this, arguments);
}